<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">

        <a-row :gutter="24" style="padding-top: 0px">
          <a-col :md="6" :sm="8">
            <a-form-item label="工单号">
              <a-input placeholder="工单号" v-model="queryParam.supplierWorkNo"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="18" :sm="16">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="showOrClose" icon="search" style='margin-left: 10px;'>高级查询</a-button>
               <a-button type="primary" icon="download" @click="handleExportXls('eip_partial_discharges')" style='margin-left: 10px;'>导出</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <a-row v-if="show">
      <a-col :md="6" :sm="8">
        <a-form-item label="物资品类类型" :label-col="{ span: 5 }" :wrapper-col="{ span: 16 }">
          <j-dict-select-tag style="width: 260px" v-model="queryParam.categoryType" placeholder="请选择品类" dictCode="categoryType"/>
        </a-form-item>
      </a-col>
      <a-col :md="6" :sm="8">
        <a-form-item label="产品厂内编号" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
          <a-input placeholder="产品厂内编号" v-model="queryParam.productModel"></a-input>
        </a-form-item>
      </a-col>
      <a-col :md="6" :sm="8">
        <a-form-item label="生产设备名称" :label-col="{ span: 6 }" :wrapper-col="{ span: 15}">
          <a-input placeholder="生产设备名称" v-model="queryParam.equipmentName"></a-input>
        </a-form-item>
      </a-col>
      <a-col :md="6" :sm="8">
        <a-form-item label="采集时间(起)" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
          <a-date-picker valueFormat="YYYY-MM-DD" v-model="queryParam.startCheckTime"></a-date-picker>
        </a-form-item>
      </a-col>
      <a-col :md="6" :sm="8">
        <a-form-item label="采集时间(止)" :label-col="{ span: 6 }" :wrapper-col="{ span: 15 }">
          <a-date-picker valueFormat="YYYY-MM-DD" v-model="queryParam.endCheckTime"></a-date-picker>
        </a-form-item>
      </a-col>
<!--      <a-col :md="6" :sm="8">-->
<!--        <a-form-item label="工序" :label-col="{ span: 5 }" :wrapper-col="{ span: 16 }">-->
<!--          <j-dict-select-tag style="width: 260px" v-model="queryParam.pdCode" placeholder="请选择工序" dictCode="testingPdCode"/>-->
<!--        </a-form-item>-->
<!--      </a-col>-->
    </a-row>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>
      <!--      :scroll="{ x: 2000,y:700}"-->
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="puid"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="toPartialDischargesDetail(record)">详情</a>
        </span>

      </a-table>
    </div>

    <eipPartialDischarges-modal ref="modalForm" @ok="modalFormOk"></eipPartialDischarges-modal>
    <eipPartialDischarges-detail v-if="showPartialDischargesDetail" ref="PartialDischargesDetail" :dataSourceDetail="dataSourceDetail" @close="closeDetail"/>
  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EipPartialDischargesModal from './modules/EipPartialDischargesModal'
  import EipPartialDischargesDetail from './modules/EipPartialDischargesDetail'
  import { getAction } from '@/api/manage'

  export default {
    name: 'EipPartialDischargesList',
    mixins: [JeecgListMixin],
    components: {
      EipPartialDischargesModal,
      EipPartialDischargesDetail
    },
    data() {
      return {
        flag:true,
        description: 'eip_partial_discharges管理页面',
        show: false,
        showPartialDischargesDetail: false,
        dataSource: [],
        dataSourceDetail: {},
        categoryTypeDict:{},            //物资品类类型数据字典
        pdCodeDict:{},                  //工序数据字典
        purchaserHqCodeDict:{},         //采购方总部编码数据字典
        startCheckTime: '',
        endCheckTime: '',
        // 表头
        columns: [
          {
            title: '供应商工单编号',
            align: 'center',
            dataIndex: 'supplierWorkNo'
          },
          {
            title: '产品厂内编号',
            align: 'center',
            dataIndex: 'productModel'
          },
          {
            title: '生产设备名称',
            align: 'center',
            dataIndex: 'equipmentName'
          },
          {
            title: '采集时间',
            align: 'center',
            dataIndex: 'checkTime',
            customRender: function(text) {
              return !text ? '' : (text.length > 10 ? text.substr(0, 10) : text)
            }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/eipPartialDischarges/list',
          delete: '/eipPartialDischarges/delete',
          deleteBatch: '/eipPartialDischarges/deleteBatch',
          exportXlsUrl: '/eipPartialDischarges/exportXls',
          importExcelUrl: 'eipPartialDischarges/importExcel',
          dictSourceUrl: '/sys/dict/getDicByCode'
        },
        dictOptions: {}
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      loadPdCode(){
        let dictParams ={ 'dictCode':'testingPdCode'}
        getAction(this.url.dictSourceUrl,dictParams).then((res)=>  {
          this.pdCodeDict  =res
        })
      },
      loadCategoryType(){
        let dictParams ={ 'dictCode':'categoryType'}
        getAction(this.url.dictSourceUrl,dictParams).then((res)=>  {
          this.categoryTypeDict  =res
        })
      },
      loadPurchaserHqCode(){
        let dictParams ={ 'dictCode':'purchaserHqCode'}
        getAction(this.url.dictSourceUrl,dictParams).then((res)=>  {
          this.purchaserHqCodeDict  =res
        })
      },
      initDictConfig() {
      },
      showOrClose() {
        this.show = !this.show
      },
      closeDetail() {
        this.showPartialDischargesDetail = false
      },
      toPartialDischargesDetail(record) {
        this.showPartialDischargesDetail = true
        this.dataSourceDetail = record
      },
      loadData(arg) {
        if (this.flag) {
          this.loadCategoryType()
          this.loadPdCode()
          this.loadPurchaserHqCode()
          this.flag = false
        }
        if (arg === 1) {
          this.ipagination.current = 1
        }
        let params = { 'pageNo': this.ipagination.current, 'pageSize': this.ipagination.pageSize }
        params = this.getQueryParams()
        this.loading=true
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            this.dataSource = res.result.records
            this.dataSource.forEach(item => {
              item.pdCode = this.pdCodeDict[item.pdCode + ""]
              item.categoryType = this.categoryTypeDict[item.categoryType]
              item.purchaserHqCode = this.purchaserHqCodeDict[item.purchaserHqCode]
            })
            this.ipagination.total = res.result.total
          }
          if (res.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading=false
        })
      }
    }

  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>
